package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.entities.AlertZone;
import zhongbo.java.air.dictionary.service.IAlertZoneService;

/**
 * @author WeiJin
 * @version 1.0
 * @date 2025/3/31 13:01
 */
@RestController
@RequestMapping("/alertZone")
@Api(tags = "禁飞区域相关接口")
public class AlertZoneController {

    @Autowired
    private IAlertZoneService alertZoneService;

    /**
     * 保存禁飞区域信息到数据库
     *
     * @param alertZone 禁飞区域信息
     * @return 返回保存的禁飞区域信息
     */
    @PostMapping("/add")
    @ApiOperation("保存禁飞区域信息")
    public ResultVo<AlertZone> saveAlertZone(@RequestBody AlertZone alertZone) {
        AlertZone resAlertZone = alertZoneService.saveAlertZone(alertZone);
        return ResultVo.ok(resAlertZone);
    }

    /**
     * 根据禁飞区域id删除禁飞区域信息
     *
     * @param id 禁飞区域id
     * @return 被删除的禁飞区域id
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除禁飞区域信息")
    public ResultVo<String> delAlertZone(String id) {
        String deletedId = alertZoneService.delAlertZone(id);
        return ResultVo.ok(deletedId);
    }

    /**
     * 修改禁飞区域信息
     *
     * @param alertZone 前端传递过来的修改信息
     * @return 修改后的信息
     */
    @PutMapping("/modify")
    @ApiOperation("修改禁飞区域信息")
    public ResultVo<AlertZone> modifyAlertZone(@RequestBody AlertZone alertZone) {
        AlertZone newAlertZone = alertZoneService.modifyAlertZone(alertZone);
        return ResultVo.ok(newAlertZone);
    }

    /**
     * 根据禁飞区域id查询禁飞区域信息
     *
     * @param id 禁飞区域id
     * @return 禁飞区域信息
     */
    @GetMapping("/query")
    @ApiOperation("根据禁飞区域id查询禁飞区域信息")
    public ResultVo<AlertZone> queryAlertZone(String id) {
        AlertZone alertZone = alertZoneService.queryById(id);
        return ResultVo.ok(alertZone);
    }

    /**
     * 分页查询禁飞区域信息
     *
     * @param pageNumber 页码
     * @param pageSize   每页记录数
     * @param zoneType   区域类型
     * @param orderBy    排序字段
     * @param orderType  排序类型，true升序 false降序 默认降序
     * @return 禁飞区域分页信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询禁飞区域信息")
    public ResultVo<PageVo<AlertZone>> pageAlertZone(
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name", required = false) String zoneType,
            @RequestParam(value = "orderBy", required = false) String orderBy,
            @RequestParam(value = "orderType", required = false, defaultValue = "false") Boolean orderType) {
        PageVo<AlertZone> alertZonePageVo = alertZoneService.pageAlertZone(pageNumber, pageSize,
                zoneType, orderBy, orderType);
        return ResultVo.ok(alertZonePageVo);
    }

}
